<?php

/**
 * 登陆
 */
class LoginAction extends Action {

    //登陆页面视图
    public function index() {
        $this->display();
    }

    //登录表单操作
    public function login() {
        if (!IS_POST)
            halt('页面不存在！');
            
        $username = I('username');
        $pwd = I('password');
        $db = M('user');
        
        $user = $db->where(array('username' => $username))->find();

        if (!$user || $user['password'] != $pwd) {
            $this->error('账号或密码错误！');
        }

//        if ($user['status'] == '1')
//            $this->error('用户已停用！');

        session('uid', $user['id']);
        session('unick', $user['username']);
        session('uaddress', $user['address']);
        session('utype', $user['status']);

        if ($user['status'] == '管理员') {
            $this->redirect('Admin/Booklist/index');
        } else {
            $this->redirect('Home/Bookinfo/index');
        }
    }

    /**
      public function verify(){
      import('ORG.Util.Image');
      Image::buildImageVerify(4, 5, 'png', 80, 25);
      }
     */
    //登出
    public function logout() {
        session_unset();
        session_destroy();
        $this->redirect('Home/Login/index');
    }

}

?>